package com.rabbit.controller;

import com.github.pagehelper.PageInfo;
import com.rabbit.annotation.Log;
import com.rabbit.constant.OperType;
import com.rabbit.service.TokenService;
import com.rabbit.util.ResultGenUtil;
import com.rabbit.vo.ResultVO;
import com.rabbit.vo.req.TokenReq;
import com.rabbit.vo.res.TokenRes;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <h1>Token管理</h1>
 *
 * @author zjw
 * @date 2022/1/18 17:29
 */
@RestController
@RequestMapping("/token")
public class TokenController {

    @Resource
    private TokenService tokenService;

    /**
     * Token列表
     */
    @PostMapping("/list")
    public ResultVO<Object> list(@RequestBody TokenReq tokenReq) {
        PageInfo<TokenRes> pageInfo = tokenService.queryTokenList(tokenReq);
        return ResultGenUtil.genSuccess(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * 注销Token
     */
    @PostMapping("/delete")
    @Log(name = "Token管理", type = OperType.DELETE)
    public ResultVO<Object> delete(@Validated @RequestBody TokenReq tokenReq) {
        tokenService.deleteToken(tokenReq);
        return ResultGenUtil.genSuccess();
    }

}
